//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#include "attrevent.h"
#include "viewattributegroup.h"
//
ViewAttributeGroup::ViewAttributeGroup(Document *doc, QObject *parent) : QObject(parent), document(doc) {
   connect(doc,SIGNAL(post_primitive_pre(Primitive*)),SLOT(doc_post_primitive_pre_view(Primitive*)));
   connect(doc,SIGNAL(post_primitive_post(Primitive*)),SLOT(doc_post_primitive_post_view(Primitive*)));
}
ViewAttributeGroup::~ViewAttributeGroup() {
   QHashIterator<ViewAttributeName,ViewAttribute*> it(attributes);
   while(it.hasNext()) {
      delete it.next().value();
   }
}
void ViewAttributeGroup::add_attribute(ViewAttribute *attr) {
   Q_ASSERT(!attributes.contains(attr->get_name()));
   attributes.insert(attr->get_name(), attr);
}
void ViewAttributeGroup::emit_value_changed(View *origin, ViewAttribute *attr) {
   Q_ASSERT(attr->get_container() == this);
   AttrValueChanged evnt(attr, origin);
   emit data_changed(&evnt);
}
void ViewAttributeGroup::doc_post_primitive_pre_view(Primitive *prim)
{
   QHashIterator<ViewAttributeName,ViewAttribute*> it(attributes);
   while(it.hasNext())
   {
      it.next().value()->handle_post_primitive_pre_view(*const_cast<const Primitive*>(prim));
   }
}
void ViewAttributeGroup::doc_post_primitive_post_view(Primitive *prim)
{
   QHashIterator<ViewAttributeName,ViewAttribute*> it(attributes);
   while(it.hasNext())
   {
      it.next().value()->handle_post_primitive_post_view(*const_cast<const Primitive*>(prim));
   }
}
